OPC Studio User's Guide and Reference
ReadMultipleItems(IEasyDAClient,ServerDescriptor,DAItemDescriptor[]) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > ReadMultipleItems Method : ReadMultipleItems(IEasyDAClient,ServerDescriptor,DAItemDescriptor[]) Method
The client object that will perform the operation.

This is typically the EasyDAClient object.

The value of this parameter cannot be null (Nothing in Visual Basic).

The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromGuid, FromString or FromServerElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

Array of OPC items involved in the operation.

Because the DAItemDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC DA item descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromString or FromDANodeElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Reads multiple named items from a single OPC server, using descriptor objects for the OPC server and OPC-DA items. Values, qualities and timestamps are returned.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function ReadMultipleItems( _
   ByVal client As IEasyDAClient, _
   ByVal serverDescriptor As ServerDescriptor, _
   ByVal itemDescriptorArray() As DAItemDescriptor _
) As DAVtqResult()
'Usage
 
Dim client As IEasyDAClient
Dim serverDescriptor As ServerDescriptor
Dim itemDescriptorArray() As DAItemDescriptor
Dim value() As DAVtqResult
 
value = IEasyDAClientExtension.ReadMultipleItems(client, serverDescriptor, itemDescriptorArray)

Parameters

client
The client object that will perform the operation.

This is typically the EasyDAClient object.

The value of this parameter cannot be null (Nothing in Visual Basic).

serverDescriptor
The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromGuid, FromString or FromServerElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

itemDescriptorArray
Array of OPC items involved in the operation.

Because the DAItemDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC DA item descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromString or FromDANodeElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Return Value

The function returns an array of OpcLabs.EasyOpc.DataAccess.OperationModel.DAVtqResult objects. The indices of elements in the output array are the same as those in the input array, itemDescriptorArray.

This method never returns null (Nothing in Visual Basic).

The individual elements of the returned value are never null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

The size of the input array will become the size of the output array. The element positions (indices) in the output array are the same as in the input array.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

 

This is a multiple-operation method. In a properly written program, it does not throw any exceptions. You should therefore not put try/catch statements or similar constructs around calls to this method. The only exceptions thrown by this method are for usage errors, i.e. when your code violates the usage contract of the method, such as passing in invalid arguments or calling the method when the state of the object does not allow it. Any operation-related errors (i.e. errors that depend on external conditions that your code cannot reliably check) are indicated in the result objects returned by the method. For more information, see Multiple-operation Methods and Do not catch any exceptions with asynchronous or multiple-operation methods.
Example
// This example measures the time needed to read 2000 items all at once, and in 20 groups by 100 items.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using System.Diagnostics;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadMultipleItems
    {
        const int NumberOfGroups = 100;
        const int ItemsInGroup = 20;
        private const int TotalItems = NumberOfGroups * ItemsInGroup;

        // Main method
        public static void TimeMeasurements()
        {
            // Make the measurements 10 times; note that first time the times might be longer.
            for (int i = 1; i <= 10; i++)
            {
                // Pause - we do not want the component to use the values it has in memory
                Thread.Sleep(2 * 1000);

                // Read all items at once, and measure the time
                var stopwatch1 = new Stopwatch();
                stopwatch1.Start();
                ReadAllAtOnce();
                stopwatch1.Stop();
                Console.WriteLine("ReadAllAtOnce has taken (milliseconds): {0}", stopwatch1.ElapsedMilliseconds);

                // Pause - we do not want the component to use the values it has in memory
                Thread.Sleep(2 * 1000);

                // Read items in groups, and measure the time
                var stopwatch2 = new Stopwatch();
                stopwatch2.Start();
                ReadInGroups();
                stopwatch2.Stop();
                Console.WriteLine("ReadInGroups has taken (milliseconds): {0}", stopwatch2.ElapsedMilliseconds);
            }

            // Example output (measured with Version 5.20, Release configuration):
            /*
                ReadAllAtOnce has taken (milliseconds): 3432
                ReadInGroups has taken (milliseconds): 1563
                ReadAllAtOnce has taken (milliseconds): 539
                ReadInGroups has taken (milliseconds): 1625
                ReadAllAtOnce has taken (milliseconds): 579
                ReadInGroups has taken (milliseconds): 1594
                ReadAllAtOnce has taken (milliseconds): 638
                ReadInGroups has taken (milliseconds): 1610   
                ...
            */

            // Note that Version 5.12 and earlier were yielding much larger penalty to repeated reads.
            // Example output (measured with Version 5.12, Release configuration):
            /*
                ReadAllAtOnce has taken (milliseconds): 4241
                ReadInGroups has taken (milliseconds): 8094
                ReadAllAtOnce has taken (milliseconds): 269
                ReadInGroups has taken (milliseconds): 7813
                ReadAllAtOnce has taken (milliseconds): 285
                ReadInGroups has taken (milliseconds): 7813
                ReadAllAtOnce has taken (milliseconds): 283
                ReadInGroups has taken (milliseconds): 7844                    
                ...
            */
        }

        // Read all items at once
        private static void ReadAllAtOnce()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            // Create an array of item descriptors for all items
            var itemDescriptors = new DAItemDescriptor[TotalItems];
            int index = 0;
            for (int iLoop = 0; iLoop < NumberOfGroups; iLoop++)
                for (int iItem = 0; iItem < ItemsInGroup; iItem++)
                    itemDescriptors[index++] = new DAItemDescriptor(
                        String.Format("Simulation.Incrementing.Copy_{0}.Phase_{1}", iLoop + 1, iItem + 1));

            // Perform the OPC read
            DAVtqResult[] vtqResults = client.ReadMultipleItems("OPCLabs.KitServer.2", itemDescriptors);

            // Count successful results
            int successCount = 0;
            for (int iItem = 0; iItem < TotalItems; iItem++)
            {
                Debug.Assert(vtqResults[iItem] != null);
                if (vtqResults[iItem].Succeeded)
                    successCount++;
            }

            if (successCount != TotalItems)
                Console.WriteLine("Warning: There were some failures, success count is {0}", successCount);
        }

        // Read items in groups
        private static void ReadInGroups()
        {
            var client = new EasyDAClient();

            int successCount = 0;
            for (int iLoop = 0; iLoop < NumberOfGroups; iLoop++)
            {
                // Create an array of item descriptors for items in one group
                var itemDescriptors = new DAItemDescriptor[ItemsInGroup];
                for (int iItem = 0; iItem < ItemsInGroup; iItem++)
                    itemDescriptors[iItem] = new DAItemDescriptor(
                        String.Format("Simulation.Incrementing.Copy_{0}.Phase_{1}", iLoop + 1, iItem + 1));

                // Perform the OPC read
                DAVtqResult[] vtqResults = client.ReadMultipleItems("OPCLabs.KitServer.2", itemDescriptors);

                // Count successful results (totalling to previous value)
                for (int iItem = 0; iItem < ItemsInGroup; iItem++)
                {
                    Debug.Assert(vtqResults[iItem] != null);
                    if (vtqResults[iItem].Succeeded) successCount++;
                }
            }

            if (successCount != TotalItems)
                Console.WriteLine("Warning: There were some failures, success count is {0}", successCount);
        }
    }
}
' This example measures the time needed to read 2000 items all at once, and in 20 groups by 100 items.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class ReadMultipleItems
        Private Const NumberOfGroups As Integer = 100
        Private Const ItemsInGroup As Integer = 20
        Private Const TotalItems As Integer = NumberOfGroups * ItemsInGroup

        ' Main method
        Public Shared Sub TimeMeasurements()
            ' Make the measurements 10 times; note that first time the times might be longer.
            For i As Integer = 1 To 10
                ' Pause - we do not want the component to use the values it has in memory
                Thread.Sleep(2 * 1000)

                ' Read all items at once, and measure the time
                Dim stopwatch1 = New Stopwatch()
                stopwatch1.Start()
                ReadAllAtOnce()
                stopwatch1.Stop()
                Console.WriteLine("ReadAllAtOnce has taken (milliseconds): {0}", stopwatch1.ElapsedMilliseconds)

                ' Pause - we do not want the component to use the values it has in memory
                Thread.Sleep(2 * 1000)

                ' Read items in groups, and measure the time
                Dim stopwatch2 = New Stopwatch()
                stopwatch2.Start()
                ReadInGroups()
                stopwatch2.Stop()
                Console.WriteLine("ReadInGroups has taken (milliseconds): {0}", stopwatch2.ElapsedMilliseconds)
            Next i

            ' Example output (measured with Version 5.20, Release configuration):
            '                
            '                    ReadAllAtOnce has taken (milliseconds): 3432
            '                    ReadInGroups has taken (milliseconds): 1563
            '                    ReadAllAtOnce has taken (milliseconds): 539
            '                    ReadInGroups has taken (milliseconds): 1625
            '                    ReadAllAtOnce has taken (milliseconds): 579
            '                    ReadInGroups has taken (milliseconds): 1594
            '                    ReadAllAtOnce has taken (milliseconds): 638
            '                    ReadInGroups has taken (milliseconds): 1610   
            '                    ...
            '                

            ' Note that Version 5.12 and earlier were yielding much larger penalty to repeated reads.
            ' Example output (measured with Version 5.12, Release configuration):
            '                
            '                    ReadAllAtOnce has taken (milliseconds): 4241
            '                    ReadInGroups has taken (milliseconds): 8094
            '                    ReadAllAtOnce has taken (milliseconds): 269
            '                    ReadInGroups has taken (milliseconds): 7813
            '                    ReadAllAtOnce has taken (milliseconds): 285
            '                    ReadInGroups has taken (milliseconds): 7813
            '                    ReadAllAtOnce has taken (milliseconds): 283
            '                    ReadInGroups has taken (milliseconds): 7844                    
            '                    ...
            '                
        End Sub

        ' Read all items at once
        Private Shared Sub ReadAllAtOnce()
            Dim client = New EasyDAClient()

            ' Create an array of item descriptors for all items
            Dim itemDescriptors = New DAItemDescriptor(TotalItems - 1) {}
            Dim index As Integer = 0
            For iLoop As Integer = 0 To NumberOfGroups - 1
                For iItem As Integer = 0 To ItemsInGroup - 1
                    itemDescriptors(index) = New DAItemDescriptor(String.Format("Simulation.Incrementing.Copy_{0}.Phase_{1}", iLoop + 1, iItem + 1))
                    index += 1
                Next iItem
            Next iLoop

            ' Perform the OPC read
            Dim vtqResults() As DAVtqResult = client.ReadMultipleItems("OPCLabs.KitServer.2", itemDescriptors)

            ' Count successful results
            Dim successCount As Integer = 0
            For iItem As Integer = 0 To TotalItems - 1
                Debug.Assert(vtqResults(iItem) IsNot Nothing)
                If vtqResults(iItem).Succeeded Then
                    successCount += 1
                End If
            Next iItem

            If successCount <> TotalItems Then
                Console.WriteLine("Warning: There were some failures, success count is {0}", successCount)
            End If
        End Sub

        ' Read items in groups
        Private Shared Sub ReadInGroups()
            Dim client = New EasyDAClient()

            Dim successCount As Integer = 0
            For iLoop As Integer = 0 To NumberOfGroups - 1
                ' Create an array of item descriptors for items in one group
                Dim itemDescriptors = New DAItemDescriptor(ItemsInGroup - 1) {}
                For iItem As Integer = 0 To ItemsInGroup - 1
                    itemDescriptors(iItem) = New DAItemDescriptor(String.Format("Simulation.Incrementing.Copy_{0}.Phase_{1}", iLoop + 1, iItem + 1))
                Next iItem

                ' Perform the OPC read
                Dim vtqResults() As DAVtqResult = client.ReadMultipleItems("OPCLabs.KitServer.2", itemDescriptors)

                ' Count successful results (totalling to previous value)
                For iItem As Integer = 0 To ItemsInGroup - 1
                    Debug.Assert(vtqResults(iItem) IsNot Nothing)
                    If vtqResults(iItem).Succeeded Then
                        successCount += 1
                    End If
                Next iItem
            Next iLoop

            If successCount <> TotalItems Then
                Console.WriteLine("Warning: There were some failures, success count is {0}", successCount)
            End If
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also